<div style="margin-top:20px">
  <form class="layui-form" id="msearchForm">
  
    <div class="layui-inline">
      <label class="layui-form-label" style="width:100px">物料编码</label>
      <div class="layui-input-inline" style="width:120px">
        <input type="text" name="code" class="layui-input"/>
      </div>
    </div>
   <div class="layui-inline">
      <label class="layui-form-label" style="width:100px">物料名称</label>
      <div class="layui-input-inline" style="width:130px;">
        <input type="text" name="name" class="layui-input"/>
      </div>
    </div>
	
    <div class="layui-inline" style="padding-left:15px;">
      <div class="layui-input-inline">
        <button class="layui-btn" id="msearchBtn" type="button">查询</button>
      </div>
    </div>
    
  </div>
 </form>
</div>
<table class="layui-table"  id="materialbomtab" lay-filter="materialbomtab">
	
</table>
<script type="text/javascript">
var ins;
$(function(){
	ins = layui.use(['table','layer','form'], function(){
		var table = layui.table;
		var form = layui.form;
		var materialInfoId = currbomtr.find("input[name='materialInfoId']").val();
		ins =table.render({ //其它参数在此省略
		 elem:"#materialbomtab",
		 url: '/eng/bom/bomversions?materialInfoId='+materialInfoId,
		 cols:[[
				{field:'companyName', width:180,title:'所属公司'},
				{field:'materialCoding', width:100, sort: true,title:'物料编号'},
				{field:'materialName',width:100,title:'物料名称'},
				{field:'materialSpec', width:135, sort: true,title:'物料规格'},
				{field:'materialBomVersion', width:135, sort: true,title:'BOM版本'},
				{field:'isDefault', width:135, sort: true,title:'是否默认BOM'},
				{field:'level', width:135, sort: true,title:'BOM级次'},
				
				{field:'brandName',width:100,title:'品牌'} ,
				{field:'materialTypeName', width:80, sort: true,title:'物料类型'},
				{field:'measurementUName', width:180, sort: true,title:'计量单位'},
				{field:'materialPriceTypeName', width:80,title:'计价方式'},
				{field:'isNoUsed', width:135, sort: true,title:'是否停用' ,templet:'#trueorfalse'},
				{field:'isSale',width:177,title:'是否可销售'},
				{field:'isBuy', width:80, sort: true,title:'是否外购'},
				{field:'isProdConsumption', width:80, sort: true,title:'是否生产耗用'},
				{field:'isVirtual', width:135, sort: true,title:'是否虚拟件 '},
				{field:'isOutsource', width:135, sort: true,title:'是否委外'},
				{field:'onHandQuantity', width:135, sort: true,title:'现存量'},
				{field:'availableQuantity', width:135, sort: true,title:'可用量'},
				{field:'minimumPackingQuantity', width:135, sort: true,title:'最小包装量'},
				{field:'ctime', width:135, sort: true,title:'创建时间'},
				{field:'remark', width:135, sort: true,title:'备注'},
		        {fixed: 'right', width:100, align:'center',toolbar: '#materialSelectBar'}
		 ]]
	    ,page: true //是否显示分页
	    ,limits: [10,20,50]
	    ,limit:10 //每页默认显示的数量
		  //where:{phone:phone}
		  //method: 'post'
		 ,done:function(res,curr,count){
			 console.log(res);
			 page = curr;
			    //得到当前页码
			 console.log(curr); 
			    //得到数据总量
			 console.log(count);
		 }
		});
		
		//物料选择 选择按钮事件
		table.on('tool(materialbomtab)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
			 var data = obj.data; //获得当前行数据
			  var layEvent = obj.event; //获得 lay-event 对应的值
			  var tr = obj.tr; //获得当前行 tr 的DOM对象
			  if(layEvent=='select'){
				  //获取数据 回填单元格
				 trobj.find("td[name='companyName']").html(data.companyName)
				.end().find("input[name='materialCode']").val(data.materialCoding)
				.end().find("td[name='materialName']").html(data.materialName)
				.end().find("td[name='materialSpec']").html(data.materialSpec)
				//设置默认数据
				.end().find("input[name='numeratorDosage']").val(1)
				.end().find("input[name='denominatorDosage']").val(1)
				.end().find("input[name='requirementDosage']").val(1)
				.end().find("input[name='productionDosage']").val(1)
				.end().find("input[name='attritionRate']").val(0)
				
				.end().find("td[name='measurementUName']").html(data.measurementUName)
				.end().find("input[name='materialBomVersion']").val(data.materialBomVersion)
				.end().find("input[name='materialInfoId']").val(data.id)
				.end().find("input[name='materialBomId']").val(data.materialBomId);
				  //关闭层
				 layer.close(bomDialogIdx);
				  
				//如果点击的是最后一行
				if(trobj.nextAll().length==0){
					$("#contentTab tbody").append($("#blankTpl tr").parent().html());
					form.render();
				}
			  }
		});
		
		$("#msearchBtn").click(function(){
			trobj = $(this).parents("tr");
		    ins.reload({url: '/pu/purchaseorder/materias',where:$("#msearchForm").serializeJson()});
		});
		
	});
	
	
	
});
</script>
<script type="text/html" id="materialSelectBar">
<a class="layui-btn layui-btn-mini" lay-event="select">选择</a>
</script>